package io.renren.modules.generator.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.MissUserDao;
import io.renren.modules.generator.entity.MissUserEntity;
import io.renren.modules.generator.service.MissUserService;


@Service("missUserService")
public class MissUserServiceImpl extends ServiceImpl<MissUserDao, MissUserEntity> implements MissUserService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = params.get("key").toString();
        IPage<MissUserEntity> page = this.page(
                new Query<MissUserEntity>().getPage(params),
                new QueryWrapper<MissUserEntity>().like(StringUtils.isNotBlank(name), "username", name)
        );

        return new PageUtils(page);
    }

    @Override
    public void banUser(Integer userId) {
        MissUserEntity missUserEntity = new MissUserEntity();
        missUserEntity.setUserId(userId);
        missUserEntity.setStatus(0);
        baseMapper.updateById(missUserEntity);
    }

    @Override
    public void startUser(Integer userId) {
        MissUserEntity missUserEntity = new MissUserEntity();
        missUserEntity.setUserId(userId);
        missUserEntity.setStatus(1);
        baseMapper.updateById(missUserEntity);
    }

}
